1 Objetivo

Apresentar o software R como uma ferramenta auxiliar para desenvolver análises estatísticas.

2 Baixar e Instalar no PC

3 No R studio

4 Dados: Leitura - Manejo - Visualização

4.1 diretorio

setwd("~/Google Drive/My Drive/Studying - Research/UTAD/Webinar-R")

4.2 xlsx

library("readxl")
FITOMAR <- read_excel("FITOMAR.xlsx")

4.3 csv

SR1 <- read.csv2("SR_FITO_N20.csv")

4.4 txt

SR2 <- read.table(file = "SR.txt",header = TRUE)
SR3 <- read_excel("SR_FITO_N21.xlsx")

4.5 salvar dados

write.csv(FITOMAR,file = "FITOMAR.csv",row.names = TRUE)

5 Manejo : Tidyverse - Dplyr

5.1 estrutura

FITOMAR%>%str
## tibble [231 × 62] (S3: tbl_df/tbl/data.frame)
##  $ Campanha         : num [1:231] 1 1 1 1 1 1 1 1 1 1 ...
##  $ Site             : chr [1:231] "A1" "A2" "A3" "A4" ...
##  $ Area             : chr [1:231] "A" "A" "A" "A" ...
##  $ latitude         : num [1:231] 494547 484554 534788 531567 529361 ...
##  $ UTM Y            : num [1:231] 8033813 8019361 8010029 8014250 8034993 ...
##  $ Profundidade     : num [1:231] 18 13 20 5 8 10 30 23 20 68 ...
##  $ Data             : chr [1:231] "43424" "43422" "43426" "43427" ...
##  $ mesano           : chr [1:231] "N18" "N18" "N18" "N18" ...
##  $ Estrato          : chr [1:231] "fundo" "fundo" "fundo" "fundo" ...
##  $ Prochloro_cito   : num [1:231] 7.37 5.42 3.66 5.57 87.14 ...
##  $ Synecho_cito     : num [1:231] 101.9 32.6 30.5 49.4 19.7 ...
##  $ Eucari_auto_cito : num [1:231] 2 1.4 3.75 2.73 0.74 1.98 1.56 1.61 1.27 6.82 ...
##  $ Bact_hete        : num [1:231] 325 230 250 329 484 ...
##  $ Eucari_hete      : num [1:231] 12.1 6.9 5.72 7.48 1.68 ...
##  $ Riq_cito_auto    : num [1:231] 84 126 134 102 78 85 111 70 77 146 ...
##  $ Div_cito_auto    : num [1:231] 24.1 32.7 35.4 28.5 26 ...
##  $ protistas_5_15um : num [1:231] NA 1550 190 NA NA ...
##  $ fito_maior_15um  : num [1:231] NA 28.8 14.9 NA NA ...
##  $ detrito          : num [1:231] NA 970 566 NA NA ...
##  $ Cl_a             : num [1:231] 0.439 0.34 0.22 0.28 0.16 ...
##  $ Cl_b             : num [1:231] 0.1039 0.0448 0.0448 0.0606 0.02 ...
##  $ Cl_c1c2          : num [1:231] 0.0415 0.037 0.0232 0.0278 0.0221 ...
##  $ Feofitina_a      : num [1:231] 0.0625 0.0536 0.0367 0.0325 0.0628 ...
##  $ DvCl_a           : num [1:231] 0 0 0 0 0.0453 ...
##  $ Cl_b/Cl_a        : num [1:231] 0.237 0.132 0.204 0.216 0.125 ...
##  $ Cl_c1c2/Cl_a     : num [1:231] 0.0945 0.1087 0.1053 0.0992 0.1382 ...
##  $ Feofitina_a/Cl_a : num [1:231] 0.143 0.157 0.167 0.116 0.392 ...
##  $ DvCl_a/Chla      : num [1:231] 0.03 0.0514 0 0.0778 0.2829 ...
##  $ Bacillariophyta  : num [1:231] NA 10.66 4.26 NA NA ...
##  $ Dinoflagellata   : num [1:231] NA 3.803 0.421 NA NA ...
##  $ Cyanophyceae     : num [1:231] NA 0.501 0 NA NA ...
##  $ Coccolithophyceae: num [1:231] NA 0 0.0255 NA NA ...
##  $ Cryptophyceae    : num [1:231] NA 0 0 NA NA ...
##  $ Chlorophyceae    : num [1:231] NA 0 0 NA NA 0 0 NA 0 0 ...
##  $ Dictyochophyceae : num [1:231] NA 0 0 NA NA 0 0 NA 0 0 ...
##  $ Thecofilosea     : num [1:231] NA 0 0 NA NA 0 0 NA 0 0 ...
##  $ Euglenophyceae   : num [1:231] NA 0 0 NA NA 0 0 NA 0 0 ...
##  $ Choanoflagellatea: num [1:231] NA 0 0 NA NA 0 0 NA 0 0 ...
##  $ flagelados       : num [1:231] NA 0.543 0 NA NA ...
##  $ Foraminifera     : num [1:231] NA 0 0.0511 NA NA ...
##  $ Ciliofora        : num [1:231] NA 0.125 0 NA NA ...
##  $ Outros           : num [1:231] NA 0.293 0 NA NA ...
##  $ S_microfito      : num [1:231] NA 24 25 NA NA 32 40 NA 34 18 ...
##  $ D_microfito      : num [1:231] NA 2.38 2.83 NA NA ...
##  $ H_microfito      : num [1:231] NA 2.72 2.13 NA NA ...
##  $ S_microfito_ciano: num [1:231] NA 26 27 NA NA 34 43 NA 36 20 ...
##  $ D_microfito_ciano: num [1:231] NA 1.43 1.5 NA NA ...
##  $ H_microfito_ciano: num [1:231] NA 0.414 0.342 NA NA ...
##  $ IPAR             : num [1:231] NA NA NA NA NA NA NA NA NA NA ...
##  $ SST              : num [1:231] NA NA NA NA NA NA NA NA NA NA ...
##  $ Kd490            : num [1:231] NA NA NA NA NA NA NA NA NA NA ...
##  $ SR               : num [1:231] NA NA NA NA NA NA NA NA NA NA ...
##  $ Amonia           : chr [1:231] "2.8773333333333331" "0.4346666666666667" "1.3086666666666666" "0.72633333333333328" ...
##  $ Nitrito          : num [1:231] 0.0853 0.1427 0.1213 0.0593 0.0413 ...
##  $ Nitrato          : chr [1:231] "0.57699999999999996" "0.51066666666666671" "0.38566666666666666" "0.22733333333333336" ...
##  $ Nitrogenio Total : num [1:231] 4.49 4.57 4.09 5.3 2.02 ...
##  $ Ortofosfato      : num [1:231] 0.1067 0.1127 0.1317 0.1963 0.0683 ...
##  $ Fosoforo Total   : num [1:231] 0.271 0.134 0.249 0.238 0.199 ...
##  $ Silicato         : num [1:231] 1.74 1.014 1.013 1.768 0.678 ...
##  $ Temperatura      : num [1:231] 26.9 26.8 26.5 26.3 25.5 ...
##  $ Salinidade       : chr [1:231] "36.94" "36.9" "36.93" "36.97" ...
##  $ Obs              : chr [1:231] "limite detecção amônia 0.05, nitrito 0.01, nitrato 0.05; valores zero indica <limite detecção" NA NA NA ...

5.2 de caracteres para numérico

FITOMAR$Amonia <- as.numeric(FITOMAR$Amonia)
FITOMAR$Nitrato <- as.numeric(FITOMAR$Nitrato)
FITOMAR$Salinidade <- as.numeric(FITOMAR$Salinidade)

FITOMAR$Amonia
##   [1]  2.87733333  0.43466667  1.30866667  0.72633333  1.10133333  1.14400000
##   [7]  0.24103333  0.40266667  1.82900000  2.22333333  0.46533333          NA
##  [13]  2.72000000  2.42666667  0.59700000  1.52075000  2.56025000  0.77400000
##  [19]  1.74425000  2.54875000          NA          NA          NA  1.90800000
##  [25]  1.85800000  2.25475000          NA  2.34000000  0.14766667  4.53983333
##  [31] 13.18516667  1.15125000  1.01075000  1.70150000  1.31950000  1.43150000
##  [37]  1.45800000  0.00000000  0.00000000  1.64400000  1.29775000          NA
##  [43]          NA          NA          NA          NA          NA          NA
##  [49]          NA          NA          NA          NA          NA          NA
##  [55]          NA          NA          NA          NA          NA          NA
##  [61]          NA          NA          NA          NA          NA          NA
##  [67]          NA          NA          NA          NA          NA          NA
##  [73]          NA          NA          NA          NA          NA          NA
##  [79]          NA          NA          NA          NA          NA          NA
##  [85]          NA          NA          NA          NA          NA          NA
##  [91]          NA  2.02866667  0.13200000  1.52366667  1.21333333  0.35300000
##  [97]  1.95766667  2.14900000  1.79600000  0.73166667          NA  0.43066667
## [103]          NA          NA  1.11400000          NA          NA          NA
## [109]          NA          NA          NA          NA          NA          NA
## [115]  0.31000000          NA  2.20366667  0.28133333          NA  0.30475000
## [121]  2.11850000  1.89450000  2.45900000  4.47850000  1.45025000          NA
## [127]          NA          NA          NA          NA  1.99700000          NA
## [133]          NA          NA          NA          NA  2.04950000          NA
## [139]          NA          NA          NA          NA          NA          NA
## [145]          NA  2.40900000          NA          NA          NA  6.14450000
## [151]          NA  2.49966667  0.07916667  4.26933333  7.93283333          NA
## [157]  1.56200000          NA          NA          NA          NA          NA
## [163]  1.03675000          NA          NA          NA          NA          NA
## [169]          NA          NA          NA  1.43983333          NA          NA
## [175]          NA  1.52225000          NA  1.06433333  0.99133333  0.07600000
## [181]          NA  1.67775000  0.94883333          NA          NA          NA
## [187]          NA          NA          NA          NA          NA          NA
## [193]          NA          NA          NA          NA  0.00000000  0.00000000
## [199]          NA          NA  0.00000000          NA  0.00000000          NA
## [205]          NA  0.00000000          NA  0.00000000  0.00000000  0.00000000
## [211]  0.00000000          NA          NA          NA          NA          NA
## [217]          NA          NA          NA          NA          NA          NA
## [223]          NA          NA          NA          NA          NA          NA
## [229]          NA          NA          NA

5.3 nome de colunas

FITOMAR%>%colnames()
##  [1] "Campanha"          "Site"              "Area"             
##  [4] "latitude"          "UTM Y"             "Profundidade"     
##  [7] "Data"              "mesano"            "Estrato"          
## [10] "Prochloro_cito"    "Synecho_cito"      "Eucari_auto_cito" 
## [13] "Bact_hete"         "Eucari_hete"       "Riq_cito_auto"    
## [16] "Div_cito_auto"     "protistas_5_15um"  "fito_maior_15um"  
## [19] "detrito"           "Cl_a"              "Cl_b"             
## [22] "Cl_c1c2"           "Feofitina_a"       "DvCl_a"           
## [25] "Cl_b/Cl_a"         "Cl_c1c2/Cl_a"      "Feofitina_a/Cl_a" 
## [28] "DvCl_a/Chla"       "Bacillariophyta"   "Dinoflagellata"   
## [31] "Cyanophyceae"      "Coccolithophyceae" "Cryptophyceae"    
## [34] "Chlorophyceae"     "Dictyochophyceae"  "Thecofilosea"     
## [37] "Euglenophyceae"    "Choanoflagellatea" "flagelados"       
## [40] "Foraminifera"      "Ciliofora"         "Outros"           
## [43] "S_microfito"       "D_microfito"       "H_microfito"      
## [46] "S_microfito_ciano" "D_microfito_ciano" "H_microfito_ciano"
## [49] "IPAR"              "SST"               "Kd490"            
## [52] "SR"                "Amonia"            "Nitrito"          
## [55] "Nitrato"           "Nitrogenio Total"  "Ortofosfato"      
## [58] "Fosoforo Total"    "Silicato"          "Temperatura"      
## [61] "Salinidade"        "Obs"
names <- FITOMAR%>%colnames()

5.4 renomear colunas

FITOMAR%>%rename(UTM_Y="UTM Y")
FITOMAR <- FITOMAR%>%rename(UTM_Y="UTM Y")
FITOMAR <- FITOMAR%>%rename(Time="mesano")

5.5 seleção/remoção de colunas

FITOMAR <- FITOMAR%>%
  dplyr::select(-c(SST,Profundidade))

5.6 categorias

SR1%>%str
## 'data.frame':    12 obs. of  10 variables:
##  $ Site        : chr  "A3" "A3" "A3" "A4" ...
##  $ Time        : chr  "F20" "F20" "M20" "M20" ...
##  $ Dist_Foz    : num  219 219 219 221 238 ...
##  $ Dist_Costa  : num  59.8 59.8 59.8 54.8 44.7 ...
##  $ latitude    : int  534788 534788 534788 531567 529361 529361 529361 453965 441761 445422 ...
##  $ Profundidade: int  20 20 24 6 8 8 8 23 22 17 ...
##  $ Chlo        : num  0.529 0.529 0.765 0.441 0.393 0.365 0.365 0.25 0.377 0.641 ...
##  $ K490        : num  0.073 0.073 0.089 0.065 0.061 0.057 0.057 0.044 0.058 0.08 ...
##  $ Ipar        : num  57.8 57.8 43.8 41.3 51 ...
##  $ SST         : num  27.1 27.1 27.8 27.5 25.7 ...
SR1$Time%>%table
## .
## F20 M20 O19 
##   6   5   1

5.7 mudar rótulo

SR1$Time[SR1$Time==c("M20")] <- "Mr20" 

5.8 manejo de variáveis

mutate-asFactor-renameLevels-renameVariables-asNumeric

SR2 <- SR2%>%
  dplyr::mutate(Time = as.factor(Campo))

levels(SR2$Time)
##  [1] "abr/19" "dez/18" "fev/19" "jul/19" "jun/19" "mar/15" "mar/16" "mar/17"
##  [9] "mar/18" "nov/18" "set/18" "set/19"

5.9 renomear rótulos

renameLevels

levels(SR2$Time) <- c("Ab19","D18","F19","Jl19","Jn19","Mr15","Mr16","Mr17","Mr18","N18", "S18", "S19")

5.10 criar novas colunas

SR3 <- SR3%>%
  as.data.frame()%>%
  rename(Dist_Foz = `Dis Foz km`, Dist_Costa = `Dis Costa km`, Profundidade = `Prof UFES`)%>%
  dplyr::mutate(SST = as.numeric(SST))

5.11 seleção de colunas

varSR <- c("Site","Time","Chlo","K490","Ipar","SST")

SR3[colnames(SR3)%in%varSR]
SR3%>%dplyr::select(all_of(varSR))

5.12 concatenar

varSR <- c("Site","Time","Chlo","K490","Ipar","SST", "Dist_Foz", "Dist_Costa","Profundidade")

SR1[colnames(SR1)%in%varSR]%>%head
SR2[colnames(SR2)%in%varSR]%>%head
SR3[colnames(SR3)%in%varSR]%>%head
SR.Mod <- rbind(SR3[colnames(SR3)%in%varSR], SR1[colnames(SR1)%in%varSR],SR2[colnames(SR2)%in%varSR])

5.13 fusão

FITO.SR <- FITOMAR%>%left_join(SR.Mod,by = c())%>%as.data.frame()
## Joining, by = c("Site", "Time")

5.14 manejo de caracteres

library(stringr)
FITO.SR$Estrato <-  toupper(substr(FITO.SR$Estrato,1,1))

5.15 salvar rda

save(list = "FITO.SR",file = "FITO_SR.rda")

6 Visualização

6.1 ggplot-resumo

rm(list = ls())
setwd("~/Google Drive/My Drive/Studying - Research/UTAD/Webinar-R")

load(file = "FITO_SR.rda")
require(GGally)
## Loading required package: GGally
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
require(dplyr)
var1 <- c(
  "Prochloro_cito",  "Synecho_cito", "Eucari_auto_cito",
  "Bact_hete","Eucari_hete",
  "Riq_cito_auto",
  "Div_cito_auto","Estrato")

FITO.SR1 <- FITO.SR%>%
          dplyr::select(all_of(var1))%>%
          na.omit()

ggpairs(FITO.SR1, columnLabels = var1, aes(color = Estrato),    # Separate data by levels of vs
        upper = list(continuous = wrap('cor', size = 3)),
        lower = list(combo = wrap("facethist", bins = 30)),
        diag = list(continuous = wrap("densityDiag", alpha = 0.5)),
        title = "Scatterplot matrix of `FITOSR` Grouped by Estrato")

6.2 Suavização - cor - transparência

ggpairs(FITO.SR1, columnLabels = var1, aes(color = Estrato,fill = Estrato),    # Separate data by levels of vs
upper = list(continuous = function(data, mapping, ...){
          ggally_cor(data=data,mapping = mapping,size=3)}),
lower = list(continuous = function(data, mapping, ...){
          ggally_smooth(data=data,mapping = mapping,alpha=0.2)}),
diag = list(continuous = function(data, mapping, ...){
          ggally_densityDiag(data=data,mapping = mapping,alpha=0.2)+
             scale_color_grey()}),
        title = "Scatterplot matrix of `FITOSR` Grouped by Estrato")

6.3 ggplot-boxplot

ww <- FITO.SR%>%
  dplyr::mutate(Area=substr(Site,1,1))%>%
  dplyr::filter(!is.na(Area))%>%
  ggplot()+
geom_boxplot(aes(x=Area,y=Riq_cito_auto,color=Estrato,fill=Estrato),
             outlier.shape = NA,size=0.5,alpha=0.3)+
scale_fill_manual(values=c("dimgrey", "gray81","ghostwhite"))+
scale_color_manual(values=c("dimgrey", "gray81","ghostwhite"))+
    geom_hline(aes(yintercept=150),size=0.5,color="blue")+
    theme_bw()+
    theme(axis.text.x = element_text(size=10,angle=0,hjust = 0.5),
          axis.text.y = element_text(size=12),
          axis.title = element_text(size=20),
          strip.text =  element_text(size=18))+
    labs(x="Área",
         y=bquote("Riqueza")
    )

ww

6.4 salvar ggplot

  ggsave(filename = paste("Riqueza.pdf",sep = ""),
         plot = ww,device = "pdf",width = 6,height = 4)

6.5 dispersão - animação

FITO.SR$Date <- as.factor(FITO.SR$Time)
levels(FITO.SR$Date) <- c("13",  
"5" ,
"13" ,
"2"  ,
"3" ,
"9"  ,
"11"  ,
"6"  ,
"6" ,
"4",
"10", 
"12" ,
"1"  ,
"8"  ,
"7",
"14" )

FITO.SR$Date <- as.integer(as.character(FITO.SR$Date))

6.6 dispersão estática

require(ggrepel)

sss1  <- FITO.SR %>% 
  dplyr::filter(!is.na(Area) & !is.na(Time) & !is.na(Div_cito_auto))%>%
  dplyr::filter(Site=="A3",Estrato=="S")%>%
  dplyr::select(Div_cito_auto,Riq_cito_auto,Date,Time)
  
sss1[-c(5),]%>%
  ggplot()+
  geom_point(aes(x=Div_cito_auto,y=Riq_cito_auto,color=Date,size=Date),show.legend = FALSE) +
  geom_text_repel(aes(x=Div_cito_auto,y=Riq_cito_auto,label=Time,color=Date,size=Date),show.legend = FALSE)

6.7 dispersão animada

sss1  <- FITO.SR %>% 
  dplyr::filter(!is.na(Area) & !is.na(Time) & !is.na(Div_cito_auto))%>%
  dplyr::filter(Site=="A3",Estrato=="S")%>%
  dplyr::select(Div_cito_auto,Riq_cito_auto,Date,Time)
  
ms <- sss1[-c(5),]%>%
  ggplot()+
  geom_point(aes(x=Div_cito_auto,y=Riq_cito_auto,color=Date,size=Date),show.legend = FALSE) +
  geom_text_repel(aes(x=Div_cito_auto,y=Riq_cito_auto,label=Time,color=Date,size=Date),show.legend = FALSE)

library(gganimate)

  u <- ms +
    transition_time(as.numeric(Date))

6.8 visualizar fig animada

animate(u, renderer = gifski_renderer())

6.9 salvar fig animada

anim_save(filename = "opo.gif",animation = u,renderer = gifski_renderer())

6.10 trajetória animada

ss  <- FITO.SR %>% 
  dplyr::filter(!is.na(Area) & !is.na(Time) & !is.na(Div_cito_auto))%>%
  dplyr::filter(Site=="A3",Estrato=="S")%>%
  dplyr::select(Div_cito_auto,Riq_cito_auto,Date,Time)%>%
  ggplot()+
    geom_point(aes(x=Div_cito_auto,y=Riq_cito_auto,color=Time,size=Date),show.legend = FALSE) +
  geom_text_repel(aes(x=Div_cito_auto,y=Riq_cito_auto,label=Time,color=Time,size=Date),show.legend = FALSE)

  t <- ss +
    geom_path(aes(y=Riq_cito_auto, x=Div_cito_auto),size=1)+
    transition_reveal(along = Date)+
  labs(title = "Year: {frame_along}")
  
    animate(t, renderer = gifski_renderer())

6.11 plotly

require(plotly)
p <- sss1[-c(5),]%>%
  plot_ly(
    y = ~Riq_cito_auto ,
    x = ~Div_cito_auto,
    #size = ~Estrato,
    size=~0.8,
    #linetype = ~Site,
    #alpha =  ~Site,
    color = ~Date,
    #split = ~Estrato,
    frame = ~paste0(sprintf("%02d", Date), " - ", Time),
    text = ~paste('Diversity:',round(Div_cito_auto*1,2),'',
                  'Riqueza:',round(Riq_cito_auto*1,2),''),
    hoverinfo = "text",
    type = 'scatter',
    mode = 'markers'
  ) %>%
  layout(
    yaxis = list(
      type = "log"
    )
  )%>%
  animation_slider(
    currentvalue = list(prefix = "Time: ", font = list(color="red"))
  )%>%
  animation_opts(
    3000, redraw = FALSE
  )

6.12 visualizar plotly

p

6.13 salvar plotly

library(htmlwidgets)

htmlwidgets::saveWidget(as_widget(p),"Riq_SST.html")

6.14 ggplot como plotly

q <-  FITO.SR %>% 
  dplyr::mutate(Area=substr(Site,1,1))%>%
  dplyr::filter(!is.na(Area) & !is.na(Time))%>%
    ggplot()+
    geom_point(aes(x=SST,y=Riq_cito_auto,color=Time))+
    geom_smooth(aes(x=SST,y=Riq_cito_auto),method = "loess")+
      facet_grid(~Area)+
  theme_bw()+
      theme(panel.grid.major = element_line(color = gray(.3), 
                                          linetype = "dashed", size = 0.1), 
          panel.background = element_rect(fill = "aliceblue"))+
    theme(axis.text.x = element_text(size=12,angle=0,hjust = 0.5),
          axis.text.y = element_text(size=12),
          axis.title = element_text(size=20),
          strip.text =  element_text(size=18))+
    labs(x="SST",
         y="Riqueza")

q

gg <- ggplotly(q)


gg

7 Estatísticas

rm(list = ls())
setwd("~/Google Drive/My Drive/Studying - Research/UTAD/Webinar-R")

load(file = "FITO_SR.rda")

varSR <- c("Site","Time","Chlo","K490","Ipar","SST")

FITO.SR%>%
  group_by(Estrato,Site,Time)%>%
summarise_at(varSR[-c(1:3)],c(mean,sum))

7.1 estatísticas por categorias

Summary1 <- FITO.SR%>%
  group_by(Estrato,Site,Time)%>%
summarise_at(varSR[-c(1:2)],c(mean))

Summary1

7.2 manejo de estatísticas - 1

require(tidyverse)
Summary2 <- Summary1%>%
  dplyr::select(Estrato,Site,Time,Chlo)%>%
  drop_na()%>%
  spread(Site,value=Chlo)

Summary2

7.3 manejo de estatísticas - 2

require(tidyverse)
Summary2%>%
  gather(key="cat",value = covar,"A1":"D9")

7.4 matriz de correlação

setwd("~/Google Drive/My Drive/Studying - Research/UTAD/Webinar-R")

load(file = "FITO_SR.rda")
require(dplyr)
var.FITO <- c(
  "Prochloro_cito",  "Synecho_cito", "Eucari_auto_cito",
  "Bact_hete","Eucari_hete",
  "Riq_cito_auto",
  "Div_cito_auto")

var.SR <- c("Site","Area","Time","Estrato",
            'Ipar','SST','K490','Dist_Costa','Dist_Foz',
            'latitude','Profundidade' )

var.Exp <- c('Ipar','SST','K490','Dist_Costa','Dist_Foz',
             'latitude','Profundidade' )

var <- c(var.SR,var.FITO)

DD <- FITO.SR%>%dplyr::select(all_of(var))%>%
  group_by(Site,Time,Estrato)%>%
  summarise_at(c(var.FITO,var.Exp),mean,na.rm=TRUE)%>%
  na.omit()%>%as.data.frame()

library(Hmisc)

cor_matrix <- rcorr(as.matrix(DD[colnames(DD)%in%c(var.FITO,var.Exp)]))

col <- colorRampPalette(c("#BB4444", "#EE9988", "#FFFFFF", "#77AADD", "#4477AA"))

library(corrplot)

corrplot(cor_matrix$r)

7.5 correlação-diagonal superior

corrplot(cor_matrix$r, method="color",col=col(200), 
         type="upper", order="hclust",diag=F,
         addCoef.col = "black", 
         addrect=2, 
         number.cex = .5, tl.cex = 1.5,cl.cex = 1.5,
         p.mat = cor_matrix$P, sig.level = 0.05, insig = "blank",
         mar=c(0,0,0,0) 
         )